package com.tingyuge.thinking.spring.dependency.source;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import javax.annotation.PostConstruct;

/**
 * ResolvableDependency 作为依赖来源
 * @author xiaodao
 * @version 1.0
 * @date 2021/7/4
 */
public class ResolvableDependencySourceDemo {

    @Autowired
    private String value;

    @PostConstruct
    public void init(){
        System.out.println(value);
    }
    public static void main(String[] args) {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
        //注册 configuration class（配置类）--->也是 spring bean
        applicationContext.register(ResolvableDependencySourceDemo.class);
        //启动应用上下文
        applicationContext.addBeanFactoryPostProcessor(beanFactory -> {
                beanFactory.registerResolvableDependency(String.class, "helloWorld");
        });
        applicationContext.refresh();

        //显示关闭应用上下文
        applicationContext.close();
    }
}
